/*
 * sensors.h
 *
 * Created: 14/07/2011 21:21:34
 *  Author: guy
 */ 



#ifndef SENSORS_H_
#define SENSORS_H_

#include <inttypes.h>
#include <math.h>

#define SEN_AX 0
#define SEN_AY 1
#define SEN_AZ 2
#define SEN_GX 3
#define SEN_GY 4
#define SEN_GZ 5
#define SEN_MX 6
#define SEN_MY 7
#define SEN_MZ 8

#define cR 0 // i.e. roll around teh x axis +ve is right wing down
#define cP 1 // pitch = rotation around teh y axis - +ve is pitch up
#define cY 2 // yaw around teh z axis - +ve is x axis moving cw towards y


//LP filter variable
// lp_alpha = dt * (RC + dt)
// RC = 1/(2*pi*Fc)
// Fc => cutoff frequency -> 2000dps ~= 10Hz
#define VAR_RC  (1) // 0.05 -> ~3rpm  ~ >500 dps

//ADXL345
#define ADXL_ADDR			0xA6
#define ADXL_ID				0xE5
#define ADXL_SENSITIVITY    (256)  // LSB/g

//L3G4200D
#define L3G4200D_ADDR			0xD2
#define L3G4200D_ID				0xD3
#define L3G4200D_MDPS_PER_DIGIT 17.5  // this value from datasheet
#define L3G4200D_SENSITIVITY    (1000/L3G4200D_MDPS_PER_DIGIT)   //LSB/DPS
#define L3G4200D_SENSITIVITYf   (1000.0f/L3G4200D_MDPS_PER_DIGIT)
#define L3G4200D_DPS_TO_RPS     (L3G4200D_MDPS_PER_DIGIT*M_PI/180.0f) //convert to mRAD PER SEC


//HMC5883L
#define HMC5883L_ADDR 0x3C
#define HMC5883L_ID1  0x48



void	populateSensorData();

void	calibrateGyro();
uint8_t adxl_init();
uint8_t l3g4200d_init();
uint8_t HMC5883L_init();

extern float sensor_data[9];  // ax,ay,az,gx,gy,gz,mx,my,mz
extern int16_t sensor_data_int[9];

#endif /* SENSORS_H_ */